package com.zutassociation.web.controller.system;

import com.zutassociation.common.core.controller.BaseController;
import com.zutassociation.common.core.domain.AjaxResult;
import com.zutassociation.common.core.page.TableDataInfo;
import com.zutassociation.common.utils.SecurityUtils;
import com.zutassociation.system.domain.Sponsor;
import com.zutassociation.system.service.SponsorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 赞助 信息操作处理
 *
 * @author 黄玉东
 * @version 1.0
 * @date 2021/2/25 18:03
 */

@RestController
@RequestMapping("/sponsor")
public class SponsorController extends BaseController {

    @Autowired
    private SponsorService sponsorService;


    /**
     * 获取赞助列表
     */
//    @PreAuthorize("@ss.hasPermi('system:sponsor:list')")
    @GetMapping("/list")
    public TableDataInfo list(Sponsor sponsor) {
        startPage();
        List<Sponsor> list = sponsorService.selectSponsorList(sponsor);
        return getDataTable(list);
    }

    /**
     * 获取上一条赞助列表
     */
//    @PreAuthorize("@ss.hasPermi('system:sponsor:query')")
    @GetMapping(value = "/getUpSponsor/{sponsorId}")
    public AjaxResult getUpSponsor(@PathVariable("sponsorId") Long sponsorId) {
        return AjaxResult.success(sponsorService.selectUpSponsor(sponsorId));
    }

    /**
     * 获取下一条赞助列表
     */
//    @PreAuthorize("@ss.hasPermi('system:sponsor:query')")
    @GetMapping(value = "/getNextSponsor/{sponsorId}")
    public AjaxResult getNextSponsor(@PathVariable("sponsorId") Long sponsorId) {
        return AjaxResult.success(sponsorService.selectNextSponsor(sponsorId));
    }

    /**
     * 根据赞助编号获取详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:sponsor:query')")
    @GetMapping(value = "/{sponsorId}")
    public AjaxResult getInfo(@PathVariable("sponsorId") Long sponsorId) {
        return AjaxResult.success(sponsorService.selectSponsorById(sponsorId));
    }

    /**
     * 新增赞助
     */
//    @PreAuthorize("@ss.hasPermi('system:sponsor:add')")
    @PostMapping
    public AjaxResult add(@Validated @RequestBody Sponsor sponsor) {
        sponsor.setCreateBy(SecurityUtils.getUsername());
        return toAjax(sponsorService.insertSponsor(sponsor));
    }

    /**
     * 修改赞助
     */
//    @PreAuthorize("@ss.hasPermi('system:sponsor:edit')")
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody Sponsor sponsor) {
        sponsor.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(sponsorService.updateSponsor(sponsor));
    }

//    @PreAuthorize("@ss.hasPermi('system:sponsor:edit')")
    @PutMapping("updateClick")
    public AjaxResult updateClick(@Validated @RequestBody Sponsor sponsor) {
        return toAjax(sponsorService.updateSponsorClick(sponsor));
    }

    /**
     * 删除赞助
     */
//    @PreAuthorize("@ss.hasPermi('system:sponsor:remove')")
    @DeleteMapping("/{sponsorIds}")
    public AjaxResult remove(@PathVariable Long[] sponsorIds) {
        return toAjax(sponsorService.deleteSponsorByIds(sponsorIds));
    }

}
